package ms.platform.dict.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import ms.platform.dict.model.DictModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;

/**
 * @author zhanglc
 * @since 0.0.1
 */
@Service
public class DictToMapService {

	@Autowired
	private DictService dictService;
	
	public Map<String, String> getMapByDictType(String dictType) {
		Map<String, String> map = Maps.newLinkedHashMap();
		DictModel d = dictService.findDictByType(dictType);
		if(d != null){
			List<DictModel> dictList = dictService.getDictByParentId(d.getId());
			for(DictModel  dl:dictList){
				if(dl==null){
					continue;
				}
				map.put(dl.getDictCode(), dl.getDictName());
			}  
		}
		return map;
	}
	
	public List<DictModel> getListByDictType(String dictType){
		List<DictModel> list = new ArrayList<DictModel>();
		Map<String, String> productTypeMap = getMapByDictType(dictType);
		for(Map.Entry<String, String> entry : productTypeMap.entrySet()){
			DictModel dictModel = new DictModel();
			dictModel.setDictCode(entry.getKey());
			dictModel.setDictName(entry.getValue());
			list.add(dictModel);
		}
		return list;
	}

}
